package com.ljf.framework.exception;

import com.ljf.framework.LjfManager;
import com.ljf.framework.log.LjfLogManager;
import com.ljf.framework.log.LjfLogService;

/**
 * 说明：处理并封装ljf框架异常，方便第三方框架直接使用
 *
 * @Auther: lijinfeng
 * @Date: 2024/4/25
 */
public class LjfExceptionHandler {
    static LjfLogService log = LjfLogManager.getLogger(LjfExceptionHandler.class);

    /**
     * 获取当前请求错误信息对应的枚举
     * @return
     */
    public static String getExceptionForServlet(){
        Object attribute = LjfManager.getLjfContext().getRequest().getAttribute("javax.servlet.error.exception");
        if (attribute == null){
            log.error("javax.servlet.error.exception属性为空");
            return null;
        }
        String message = attribute.toString();
        String substring = message.substring(message.lastIndexOf(":")+2);// 这里有一个冒号和一个空格
        return substring;
    }
}
